package com.pj.controller;

import com.pj.AjaxResult;
import com.pj.service.CrawlService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("crawl")
@RequiredArgsConstructor // 当本类中会使用多个Autowired注解时可使用本注解,然后引入时是final类型即可,lombok注解!

public class CrawlController {

    private final CrawlService crawlService;

    /**
     * @Author szy
     * @Description  开启爬虫
     * @Date 11:16 2022/10/21
     * @Param [sourceId, sourceStatus]
     * @return com.pj.AjaxResult
     **/
    @PostMapping("openOrCloseCrawl")
    public AjaxResult openOrCloseCrawl(Integer sourceId, Byte sourceStatus){
        crawlService.openOrCloseCrawl(sourceId,sourceStatus);
        return AjaxResult.success();
    }


    @GetMapping("startCloseCrawl")
    public AjaxResult startCloseCrawl(Integer sourceId){
        boolean startFlag = crawlService.startCloseCrawl(sourceId);
        if(startFlag){
            return AjaxResult.success("开启爬虫成功能");
        }else {
            return AjaxResult.error("开始爬虫失败");
        }
    }


    @GetMapping("openCloseCrawl")
    public AjaxResult openCloseCrawl(Integer sourceId){
        boolean startFlag = crawlService.openCloseCrawl(sourceId);
        if(startFlag){
            return AjaxResult.success("开启爬虫成功能");
        }else {
            return AjaxResult.error("开始爬虫失败");
        }
    }






}
